package com.tobeface.wechat.message;

import com.tobeface.modules.lang.Requires;

import java.nio.charset.Charset;

/**
 * @author loudyn
 */
public abstract class AbstractMessageChannel implements WeChatMessageChannel {

    @Override
    public final void write(String result) {
        Requires.notNull(result, "result must not null!");
        write(result, Charset.forName("UTF-8"));
    }

    @Override
    public final void writeMessage(WeChatMessage outMessage) {
        Requires.notNull(outMessage, "outMessage must not null!");
        String messagestr = WeChatMessagePayloadHelper.dumps(
                outMessage.getPayloads()
        );
        write(messagestr);
    }
}
